package com.paginasenlanube.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.hibernate.FetchMode;
import org.hibernate.annotations.CollectionId;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.Type;



@Entity
@Table(name = "menu")
public class Menu implements Serializable{
	
  /**
	 * 
	 */
  private static final long serialVersionUID = 1L;
  private long id;
  private Set<Page> pageList = new HashSet<Page>();
  private Image image;
  
  public Menu(){
	  
  }

  @OneToOne(cascade = CascadeType.ALL)
  public Image getImage() {
    return image;
  }

  public void setImage(Image value) {
    this.image = value;
  }

  @Id
  @GeneratedValue
  @Column(name = "id")
  public long getId() {
	return id;
  }

  public void setId(long id) {
	this.id = id;
  }


  @OneToMany(mappedBy="menu_id",fetch = FetchType.EAGER)
  @OrderBy("position ASC")
  public Set<Page> getPageList() {
	return pageList;
  }



  public void setPageList(Set<Page> pageList) {
	this.pageList = pageList;
  }
  
  public Page getPage(long id){
	  Page page = null;
	  for(Page p :pageList){
		  if(p.getId() == id){
			 page = p; 
		  }
	  }
	  return page;
  }

}
